
[dbo].[asi_CreateGLExportItems]
CREATE PROCEDURE [dbo].[asi_CreateGLExportItems]
@glExportKey uniqueidentifier
AS
DECLARE
@FinancialEntityKey uniqueidentifier,
@BeginDate datetime,
@EndDate datetime
SELECT @BeginDate = BeginDate, @EndDate = EndDate, @FinancialEntityKey = FinancialEntityKey FROM GLExport WHERE GLExportKey = @glExportKey
DELETE GLExportItem Where GLExportKey = @glExportKey
BEGIN
INSERT INTO GLExportItem(GLExportKey, GLTransactionKey)
SELECT @glExportKey AS GLExportKey, GLTransactionKey
FROM GLTransactionMain
WHERE FinancialEntityKey = @FinancialEntityKey AND DATEDIFF(Day,TransactionDate, @EndDate) >= 0 AND DATEDIFF(Day,TransactionDate, @BeginDate) <= 0 AND GLTransactionKey NOT IN (SELECT GLTransactionKey FROM GLExportItem) ORDER BY TransactionDate
END
GO